import ExcelJS from 'exceljs';

export const exportExcel = async () => {
  // 创建工作簿
  const workbook = new ExcelJS.Workbook();

  // 添加工作表
  const worksheet = workbook.addWorksheet('产品列表');

  // 设置表头
  worksheet.columns = [
    { header: '产品名称', key: 'name', width: 20 },
    { header: '价格', key: 'price', width: 10 },
    { header: '库存', key: 'stock', width: 10 }
  ];

  // 添加数据行
  worksheet.addRow({ name: '智能手机', price: 2999, stock: 100 });
  worksheet.addRow({ name: '笔记本电脑', price: 5999, stock: 50 });
  worksheet.addRow({ name: '平板电脑', price: 1999, stock: 80 });

  // 导出Excel文件
  const buffer = await workbook.xlsx.writeBuffer();
  const blob = new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });

  const link = document.createElement('a')
  link.href = URL.createObjectURL(blob)
  link.download = `产品数据.xlsx`
  link.click()

  console.log('导出成功')
}

export const importExcel = () => {

}

const useExcel = () => {

  return {

  }
}


export default useExcel